<?php
$auth = $_SESSION['auth'];
if($auth<90)
{
	echo '<center>Non hai l\'autorizzazione per accedere a questa pagina.<br><br><img src="images/accesso_negato.gif"></center>';
	exit();
}
?>


<div id="wrapper">
    	<div id="secWrapper">
        	<div id="container" class="clearfix">
            	<div id="mainCol" class="clearfix">
				    
		<h3 id="why">Registro Contabile - Cerca Operazione</h3><br>
                   
		<font size="2">
		
	<form name="cercaper">
	Cerca per:
		<select name="ricercaper" onChange="validateForm()">
			<option value="tipo">Tipo </option>
			<option value="causale">Causale </option>
			<option value="importo">Importo </option>
			<option value="data">Data </option>
		</select>
	</form>
	
	<div id="tipo" style="display:block;">
	<form name="tipo" method="post">
	<br>Tipo: <select name="ricercatipo" onkeydown="if(event.keyCode==13) validateForm2('tipo')"><option value="entrata">entrata</option><option value="uscita">uscita</option></select>
	<br><br><input type="button" value="Cerca" onClick="validateForm2('tipo')">
	</form>
	</div>
	
	<div id="causale" style="display:none;">
	<form name="causale" method="post">
	<br>Causale: <input type="text" size="50" name="causale" onkeydown="if(event.keyCode==13) validateForm2('causale')">
	<br><br><input type="button" value="Cerca" onClick="validateForm2('causale')">
	</form>
	</div>
	
	<div id="importo" style="display:none;">
	<form name="importo" method="post">
	<br>Importo: <input type="text" size="4" name="importo" onkeydown="if(event.keyCode==13) validateForm2('importo')">
	<br><br><input type="button" value="Cerca" onClick="validateForm2('importo')">
	</form>
	</div>
	
	<div id="data" style="display:none;">
	<form name="data" method="post">
	<br>Data: <select name="giorno" onkeydown="if(event.keyCode==13) validateForm2('data')"><option value="<?php echo date(d) ?>"><?php echo date(d) ?></option><?php for($i=1; $i<=31; $i++) { ?> <option value="<?php echo $i ?>"><?php echo $i; ?> </option> <?php } ?></select>
			<select name="mese" onkeydown="if(event.keyCode==13) validateForm2('data')"><option value="<?php echo date(m) ?>"><?php echo date(m) ?></option><?php for($i=1; $i<=12; $i++) { ?> <option value="<?php echo $i ?>"><?php echo $i; ?> </option> <?php } ?></select>
			<select name="anno" onkeydown="if(event.keyCode==13) validateForm2('data')">
				<option value="<?php echo date(Y); ?>"><?php echo date(Y); ?></option>
				<option value="<?php echo date(Y)-1; ?>"><?php echo date(Y)-1; ?></option>
			</select> 
	<br><br><input type="button" value="Cerca" onClick="validateForm2('data')">
	</form>
	</div>
	
	<br><a href="home.php?page=contabilita">Indietro</a>
	
		</font>
                </div>
		
<script language="Javascript">
function validateForm() 
	{
		//acquisisco il valore delle variabili
		var form = document.cercaper.ricercaper[document.cercaper.ricercaper.selectedIndex].value;
	    
		//controllo coerenza 
		if (form == "tipo") 
		{
			document.getElementById("causale").style.display='none';
			document.getElementById("importo").style.display='none';
			document.getElementById("data").style.display='none';
			document.getElementById("tipo").style.display='block';
		}
		else if (form == "causale") 
		{
			document.getElementById("tipo").style.display='none';
			document.getElementById("importo").style.display='none';
			document.getElementById("data").style.display='none';
			document.getElementById("causale").style.display='block';
		}
		else if (form == "importo") 
		{
			document.getElementById("causale").style.display='none';
			document.getElementById("tipo").style.display='none';
			document.getElementById("data").style.display='none';
			document.getElementById("importo").style.display='block';
		}
		else if (form == "data") 
		{
			document.getElementById("causale").style.display='none';
			document.getElementById("importo").style.display='none';
			document.getElementById("tipo").style.display='none';
			document.getElementById("data").style.display='block';
		}	
	}
	
function validateForm2(search) 
	{
		//acquisisco il valore delle variabili
		if(search == "causale")
		{
			var type = document.forms[search].causale.value;
			if(type == "")
			{
				alert("Il campo causale non puo' essere vuoto");
				document.forms[search].causale.focus();
				return false;
			}
		}
		else if(search == "importo")
		{
			var type = document.forms[search].importo.value;
			if(type == "")
			{
				alert("Il campo importo non puo' essere vuoto");
				document.forms[search].importo.focus();
				return false;
			}
		}
	    
		//mando i dati alla pagina
		document.forms[search].action = "home.php?page=cercaoperazione2&search="+search;
		document.forms[search].submit();
	}
	
</script>
                   
                